#include <bits/stdc++.h>
// 2025/01/20
// tag: 
// Author: Zhang Muen
// You are my sunshine, my only sun shine 
using namespace std;

int64_t n, road[100002];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int64_t cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> road[i];
    for (int i = 2; i <= n; i++)
        if (road[i] > road[i - 1])
            cnt += road[i] - road[i - 1];
    cout << road[1] + cnt;
    return 0;
}